package service.impl;/*
 *86180
 *2021/10/2
 *18:43
 */

import Dao.impl.UserDaoImpl;
import Dao.UserDao;
import entity.User;
import service.UserService;
import util.DruidUtil;

public class UserServiceImpl implements UserService {
    private UserDao userDao=new UserDaoImpl();
    @Override
    public User login(String username, String password) {
        User user=null;
        user = userDao.select(username);
        if(user!=null){
            if(user.getPassword().equals(password)){
                return user;
            }
        }
        DruidUtil.close();
        return null;
    }

    @Override
    public int updatePassword(String username, String newPassword) {
        int result=0;
        try {
            DruidUtil.begin();
            result=userDao.update(username, newPassword);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }
}
